package com.shop.convert;

import java.util.Map;

import org.apache.struts2.util.StrutsTypeConverter;

import com.shop.entity.Point;

public class PointConverter extends StrutsTypeConverter {

	//从字符串转化成对象
	//context Action执行的环境 容器 
	//values[] 表单提交的数据
	//Class toClass目标对象
	@Override
	public Object convertFromString(Map context, String[] values, Class toClass) {
		if (toClass == Point.class) {
			String data  =values[0];//第一个数据  101,202
			String [] arr  =data.split(",");
			Point point = new Point(Integer.parseInt(arr[0]),Integer.parseInt(arr[1]) ) ;
			return point;
		}
		return null;
	}

	//对象转换成字符串
	@Override
	public String convertToString(Map context, Object o) {
		return o.toString();
	}

}
